<template>
  <div id="app">
   <h1>{{num}}</h1>
   <br>
   <button @click="addNum">加</button>
   <button v-on:click="subNum">减</button>
   <button @click="asycnAddNum">异步加</button>
   <br>
    <h1>{{num|isAddOrOdd}}</h1>
  </div>
</template>

<script>
import HelloWorld from './components/HelloWorld.vue'

export default {
  data:function(){
    return {
      num: 233
    }
  },
  filters:{
    isAddOrOdd:function(value){
      return value % 2 ? "奇数" : "偶数"
    }
  },
// 计算属性实现
/*   computed:{
    isAddOrOdd:function(){
      return this.num % 2 ? "奇数" : "偶数" 
    }
  }, */
// 过滤器实现

  methods:{
    addNum:function(){
      this.num++
    },
    subNum:function(){
      this.num--
    },
    asycnAddNum:function(){
      let _this = this
      setTimeout(function(){
        _this.addNum()
      },3000)
    }
  },
  name: 'App',
  components: {

  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
